# from xml.dom import minidom
#
# from django.test import TestCase
#
# class GameDescription:
#     i512x512 = "512x512"
#     i175x175 = "175x175"
#     i72x72 = "72x72"
#     i480x320 = "480x320"
#     i320x480 = "320x480"
#
#     def __init__(self, xmlstr=None):
#         self.description = None
#         self.icons = {GameDescription.i512x512: None,
#                       GameDescription.i175x175: None,
#                       GameDescription.i72x72: None}
#         self.screenshots = {
#             GameDescription.i480x320: [],
#             GameDescription.i320x480: []
#         }
#         if xmlstr:
#             for node in minidom.parseString(xmlstr).getElementsByTagName('info'):
#                 attrs = {}
#                 for xattr in node.attributes.values():
#                     attrs[xattr.name] = xattr.value
#                 self.set_description(attrs['description'])
#                 for n in node.childNodes:
#                     if n.tagName == 'icons':
#                         for imgNode in n.childNodes:
#                             if imgNode.tagName == 'image':
#                                 attrs = {}
#                                 for xattr in imgNode.attributes.values():
#                                     attrs[xattr.name] = xattr.value
#                                 self.set_icon(attrs['size'], attrs['path'])
#                     elif n.tagName == 'screenshots':
#                         for imgNode in n.childNodes:
#                             if imgNode.tagName == 'image':
#                                 attrs = {}
#                                 for xattr in imgNode.attributes.values():
#                                     attrs[xattr.name] = xattr.value
#                                 self.add_screenshot(attrs['size'], attrs['path'])
#                     # if n.nodeType == 1:
#                     #     retparms[n.tagName] = (n.childNodes)[0].nodeValue
#     #设置描述信息
#     def set_description(self, desc):
#         self.description = desc
#
#     #设置图标
#     def set_icon(self, size, path):
#         self.icons[size] = path
#
#     #设置截图
#     def add_screenshot(self, size, path):
#         self.screenshots[size].append(path)
#
#     def to_string(self):
#         str = '<info description=\"{0}\">'.format(self.description)
#         str += '<icons>'
#         for key in self.icons.keys():
#             str += '<image size=\"{0}\" path=\"{1}\" />'.format(key, self.icons[key])
#         str += '</icons>'
#         str += '<screenshots>'
#         if len(self.screenshots[GameDescription.i480x320]):
#             for img in self.screenshots[GameDescription.i480x320]:
#                 str += '<image size=\"{0}\" path=\"{1}\" />'.format(GameDescription.i480x320, img)
#         if len(self.screenshots[GameDescription.i320x480]):
#             for img in self.screenshots[GameDescription.i320x480]:
#                 str += '<image size=\"{0}\" path=\"{1}\" />'.format(GameDescription.i320x480, img)
#         str += '</screenshots>'
#         str += '</info>'
#         return str
# # Create your tests here.
#
# gameinfo = GameDescription()
# gameinfo.set_description("this is a test")
# gameinfo.set_icon(GameDescription.i512x512, "how are you")
# gameinfo.set_icon(GameDescription.i72x72, "ni hao")
# gameinfo.set_icon(GameDescription.i175x175, "good")
#
# gameinfo.add_screenshot(GameDescription.i480x320, "this is a picture")
# print (gameinfo.to_string())
#
#
# gameinfo = GameDescription('<info description="this is a test"><icons><image size="72x72" path="ni hao" /><image size="175x175" path="good" /><image size="512x512" path="how are you" /></icons><screenshots><image size="480x320" path="this is a picture" /></screenshots></info>')
# print(str(gameinfo.icons))
# print(str(gameinfo.screenshots))
# print(str(gameinfo.description))
